<!-- 素材库弹窗组件 -->
<template>
  <a-modal
    :maskClosable="false"
    :title="fileSource === 'image' ? '选择图片' : '选择视频'"
    centered
    :bodyStyle="{ padding: 0 }"
    :width="1220"
    v-model="visible"
    @ok="submit"
  >
    <Warehouse ref="Warehouse" :limit="limit" hideCardTab @closeModal="visible = false" />
  </a-modal>
</template>

<script>
import Warehouse from '@/views/content/warehouse'
export default {
  components: {
    Warehouse
  },
  props: {
    // 限制素材库勾选数量 0则不限制
    limit: {
      type: Number,
      default: 1
    },
    // image || video
    fileSource: {
      type: String,
      default: 'image'
    }
  },
  data() {
    return {
      visible: false,
      checkedItems: []
    }
  },
  methods: {
    show() {
      this.visible = true;

      this.$nextTick(()=>{
        this.$refs.Warehouse.onTabChange(this.fileSource === 'image' ? '1' : '0'); // 切换成要选的素材类型
        this.$refs.Warehouse.checkedIds = [];
        this.$refs.Warehouse.checkedRows = [];
      })
    },
    // 确认选择图片
    submit() {
      const { checkedRows } = this.$refs.Warehouse
      if(checkedRows.length){
        this.$emit('select', checkedRows.map(v=> v.url));
      }
      this.visible = false;
    }
  }
}
</script>

<style lang="scss" scoped></style>
